package com.jeethink.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.jeethink.common.annotation.Log;
import com.jeethink.common.enums.BusinessType;
import com.jeethink.subject.domain.SysSubject;
import com.jeethink.subject.service.ISysSubjectService;
import com.jeethink.common.core.controller.BaseController;
import com.jeethink.common.core.domain.AjaxResult;
import com.jeethink.common.utils.poi.ExcelUtil;
import com.jeethink.common.core.page.TableDataInfo;

/**
 * 课题管理Controller
 *
 * @author Xianlu Tech
 * @date 2020-04-23
 */
@Controller
@RequestMapping("/subject/subject")
public class SysSubjectController extends BaseController {
    private String prefix = "subject/subject";

    @Autowired
    private ISysSubjectService sysSubjectService;

    @RequiresPermissions("subject:subject:view")
    @GetMapping()
    public String subject() {
        return prefix + "/subject";
    }

    /**
     * 查询课题管理列表
     */
    @RequiresPermissions("subject:subject:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysSubject sysSubject) {
        startPage();
        List<SysSubject> list = sysSubjectService.selectSysSubjectList(sysSubject);
        return getDataTable(list);
    }

    /**
     * 导出课题管理列表
     */
    @RequiresPermissions("subject:subject:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SysSubject sysSubject) {
        List<SysSubject> list = sysSubjectService.selectSysSubjectList(sysSubject);
        ExcelUtil<SysSubject> util = new ExcelUtil<SysSubject>(SysSubject.class);
        return util.exportExcel(list, "subject");
    }

    /**
     * 新增课题管理
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存课题管理
     */
    @RequiresPermissions("subject:subject:add")
    @Log(title = "课题管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SysSubject sysSubject) {
        return toAjax(sysSubjectService.insertSysSubject(sysSubject));
    }

    /**
     * 修改课题管理
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        SysSubject sysSubject = sysSubjectService.selectSysSubjectById(id);
        mmap.put("sysSubject", sysSubject);
        return prefix + "/edit";
    }

    /**
     * 修改保存课题管理
     */
    @RequiresPermissions("subject:subject:edit")
    @Log(title = "课题管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SysSubject sysSubject) {
        return toAjax(sysSubjectService.updateSysSubject(sysSubject));
    }

    /**
     * 删除课题管理
     */
    @RequiresPermissions("subject:subject:remove")
    @Log(title = "课题管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(sysSubjectService.deleteSysSubjectByIds(ids));
    }
}
